local awful = require("awful")
local ass = awful.spawn

local bl = {}

function bl.switcher(sw)
    if sw then
        ass("rfkill unblock bluetooth")
        ass("bluetoothctl power on")
    else
        ass("rfkill block bluetooth")
        ass("bluetoothctl power off")
    end
end

function bl.get()
    return io.popen("rfkill | grep bluetooth | cut -d ' ' -f 7"):read("*all")
end

function bl.toggle()
    status = bl.get()
    if status == "unblocked" then
        bl.switcher(false)
    else
        bl.switcher(true)
    end
end

return bl
